package com.rabbit.validate.phone;

import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * <h1>手机号校验</h1>
 *
 * @author zjw
 * @date 2022/2/18 8:29
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    private static final Pattern PHONE_PATTERN = Pattern.compile("1\\d{10}");

    @Override
    public boolean isValid(String mobile, ConstraintValidatorContext constraintValidatorContext) {
        return StringUtils.hasLength(mobile) && PHONE_PATTERN.matcher(mobile).matches();
    }

}
